package com.micro.school.system.api.factory;

import com.micro.school.system.api.domain.vo.MerMerchantVos;
import com.micro.school.system.api.domain.StudentInfos;
import com.micro.school.system.api.domain.vo.StudentInfoVos;
import com.micro.school.system.api.domain.vo.StudentPayVos;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.cloud.openfeign.FallbackFactory;
import org.springframework.stereotype.Component;
import com.micro.school.common.core.domain.R;
import com.micro.school.system.api.RemoteUserService;
import com.micro.school.system.api.domain.SysUser;
import com.micro.school.system.api.model.LoginUser;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestBody;

import java.util.List;

/**
 * 用户服务降级处理
 *
 * @author upupgo
 */
@Component
public class RemoteUserFallbackFactory implements FallbackFactory<RemoteUserService>
{
    private static final Logger log = LoggerFactory.getLogger(RemoteUserFallbackFactory.class);

    @Override
    public RemoteUserService create(Throwable throwable)
    {
        log.error("用户服务调用失败:{}", throwable.getMessage());
        return new RemoteUserService()
        {
            @Override
            public R<LoginUser> getUserInfo(String username, String source)
            {
                return R.fail("获取用户失败:" + throwable.getMessage());
            }

            @Override
            public R<Boolean> registerUserInfo(SysUser sysUser, String source)
            {
                return R.fail("注册用户失败:" + throwable.getMessage());
            }

            @Override
            public R<Boolean> recordUserLogin(SysUser sysUser, String source)
            {
                return R.fail("记录用户登录信息失败:" + throwable.getMessage());
            }

            @Override
            public R<StudentInfos> queryStudent(StudentInfoVos studentInfoVos) {
                return null;
            }

            @Override
            public R<List<StudentInfoVos>> queryVosByIdNumber(StudentInfoVos studentInfoVos) {
                return null;
            }


            @Override
            public R<MerMerchantVos> queryMerMerchantById(Integer id) {
                return R.fail("查询商户失败:" + throwable.getMessage());
            }
            @Override
            public R<List<StudentInfos>> listStudentLimitById(StudentInfos studentInfoVo){
                return R.fail("查询学生失败:" + throwable.getMessage());
            }
            /**
             *
             * 一次查询多个学生
             * */
            @GetMapping(value = "/info/queryStudentByIds")
            public R<List<StudentInfos>> queryStudentByIds(@RequestBody List<Long> ids){
                return R.fail("查询学生失败:" + throwable.getMessage());
            }

            @Override
            public R<MerMerchantVos> queryMerchantById(Long id) {
                return R.fail("查询商户失败:" + throwable.getMessage());
            }

            @Override
            public void insertStudentPayVos(List<StudentPayVos> data) {

            }

            @Override
            public void updateStudentPayVos(List<StudentPayVos> data) {

            }

            @Override
            public StudentInfoVos selectSchoolById(Long id) {
                return null;
            }

            @Override
            public void updateAllStudentInfoCollegeName(String collegeName, Long collegeId, String oldCollegeName) {
                log.error("修改学院名称失败:{}", collegeName);
            }

            @Override
            public void updateAllCollegeMajor(String majorName, Long id, String oldMajorName) {

            }

            @Override
            public void updateAllCollegeModel(String modelName, Long id, String oldModelName) {

            }

            @Override
            public void updateAllCampusName(String campusName, Long id, String oldCampusName) {

            }

            @Override
            public void updateAllSchoolGrade(String grade, Long id) {

            }
        };
    }
}
